package by.amakarevich.services.impl;

import javax.inject.Inject;

import org.apache.commons.lang3.Validate;
import org.springframework.stereotype.Service;

import by.amakarevich.dataaccess.CanvasDao;
import by.amakarevich.dataaccess.ProductDao;
import by.amakarevich.datamodel.Canvas;
import by.amakarevich.datamodel.Product;
import by.amakarevich.services.CanvasService;

@Service
public class CanvasServiceImpl implements CanvasService{
	@Inject
	private CanvasDao canvasDao;
	
	@Inject
	private ProductDao productDao;
	
	@Override
	public void createNewCanvas(Canvas canvas,  Product product) {
		Validate.isTrue(canvas.getId() == null, "This method should be called for 'not saved yet' profile only. Use UPDATE instead");
		canvas.setProduct(product);
		canvasDao.insert(canvas);
	}

	@Override
	public Canvas get(Long id) {
		return canvasDao.getById(id);
	}

	@Override
	public void updateCanvas(Canvas canvas) {
		canvasDao.update(canvas);
	}

	@Override
	public void removeCanvas(Long id) {

		canvasDao.delete(id);
		productDao.delete(id);

	}
	  @Override
	    public void deleteAll() {
		  canvasDao.deleteAll();
		  productDao.deleteAll();
	    }
}
